<template>
    <div class="chat-sidebar">
        <div class="assistant-profile">
            <div class="avatar">
                <img src="/api/placeholder/60/60?text=AI" alt="AI助手" />
            </div>
            <div class="assistant-info">
                <h3>智能助手小盟</h3>
                <p>我是您的专属AI助手</p>
            </div>
        </div>

        <div class="conversation-history">
            <h4>💬 对话历史</h4>
            <div class="history-list">
                <div v-for="conversation in conversations" :key="conversation.id" class="history-item"
                    :class="{ active: currentConversationId === conversation.id }"
                    @click="emit('load-conversation', conversation)">
                    <div class="history-title">{{ conversation.title }}</div>
                    <div class="history-time">{{ conversation.lastTime }}</div>
                </div>
            </div>
            <el-button @click="emit('new-conversation')" style="width: 100%; margin-top: 10px;">
                <el-icon>
                    <Plus />
                </el-icon> 新建对话
            </el-button>
        </div>

        <div class="assistant-settings">
            <h4>⚙️ 助手设置</h4>
            <div class="setting-item">
                <span>语音播报</span>
                <el-switch :value="voiceEnabled" @update:modelValue="emit('update:voiceEnabled', $event)"
                    size="small" />
            </div>
        </div>
    </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';
import { Plus } from '@element-plus/icons-vue';

defineProps({
    conversations: {
        type: Array,
        default: () => []
    },
    currentConversationId: {
        type: [Number, String],
        default: null
    },
    voiceEnabled: {
        type: Boolean,
        default: false
    }
});

const emit = defineEmits(['load-conversation', 'new-conversation', 'update:voiceEnabled']);
</script>

<style scoped>
.chat-sidebar {
    width: 280px;
    background-color: #f5f7fa;
    padding: 20px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e0e0e0;
}

.assistant-profile {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

.avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 15px;
}

.avatar img {
    width: 100%;
    height: 100%;
}

.assistant-info h3 {
    margin: 0 0 5px 0;
}

.assistant-info p {
    margin: 0;
    font-size: 13px;
    color: #666;
}

.conversation-history {
    flex-grow: 1;
}

.conversation-history h4 {
    margin-top: 0;
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
}

.history-item {
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 5px;
}

.history-item:hover {
    background-color: #e9ecef;
}

.history-item.active {
    background-color: #409eff;
    color: white;
}

.history-title {
    font-weight: bold;
    font-size: 14px;
}

.history-time {
    font-size: 12px;
    opacity: 0.7;
}

.assistant-settings {
    margin-top: 20px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 14px;
}
</style>